package config

import (
	"fmt"
	"io/ioutil"
	"time"

	"github.com/pelletier/go-toml"
)

type Platform struct {
	Name string `toml:"name"`
}
type Keys struct {
	PublicKey  string `toml:"publicKey"`
	PrivateKey string `toml:"privateKey"`
}
type Gloabl struct {
	InstanceID []string `toml:"instanceID"`
}
type Backup struct {
	BackupStatus          string `toml:"backupStatus"`
	BackupMode            string `toml:"backupMode"`
	BackupType            string `toml:"backupType"`
	BackupStrategy        string `toml:"backupStrategy"`
	BackupMethod          string `toml:"backupMethod"`
	BackupStorePath       string `toml:"backupStorePath"`
	BackupDownloadNetType string `toml:"backupDownloadNetType"`
}
type Redis struct {
	Addr                string        `toml:"addr"`
	Password            string        `toml:"password"`
	Db                  int           `toml:"db"`
	Expire              time.Duration `toml:"expire"`
	AlreadyDownloadJobs string        `toml:"alreadyDownloadJobs"`
	CreatedBackupJobs   string        `toml:"createdBackupJobs"`
}
type Config struct {
	PlatForm Platform `toml:"platform"`
	Keys     Keys     `toml:"keys"`
	Global   Gloabl   `toml:"global"`
	Backup   Backup   `toml:"backup"`
	Redis    Redis    `toml:"redis"`
}

var ConfigInfo Config

func init() {
	ConfigInfo = Config{}
	b, err := ioutil.ReadFile("config.toml")
	if err != nil {
		fmt.Printf("read config file error: %s\n", err)
		return
	}
	err = toml.Unmarshal(b, &ConfigInfo)
	if err != nil {
		fmt.Printf("load config file error: %s", err)
		return
	}
	//fmt.Println(ConfigInfo)
}
